<?php
$ws = new Swoole\WebSocket\Server('0.0.0.0',9200);
$ws->on('Open',function ($ws,$request){
    echo "第-{$request->fd} 用户已经进入聊天室";
});

$ws->on('Message',function ($ws,$frame){
    $data = $frame->data;
    $ret ['data'] = $data;
    foreach($ws->connections as $client){
        if ($frame->fd == $client){
            $ret['style'] = "bubble me";
        }else{
            $ret['style'] = "bubble you";
        }
        @$ws->push($client,json_encode($ret,256));
    }
});

$ws->on('Close',function ($ws,$fd){
   echo "第-{$fd} 用户已经离开聊天室";
});

$ws->start();
